


/**
 * primitive Circle 大量加载
 * 
 */
import Primitive from "../Primitive"

const DEFAULT_STYLE = {

}

export default class CirclePrimitive extends Primitive {
  /**
   * 
   * @param {*} positions 
   * @param {*} radius 
   */
  constructor(positions, radius, options = {}) {
    super()
    this._positions = positions
    this._radius = radius
    this._type = 'circle_primitive'
    this._style = {
      ...DEFAULT_STYLE,
      ...options
    }

    this.delegate = new Cesium.Primitive({
      geometryInstances: new Cesium.GeometryInstance({
        geometry: new Cesium.EllipseGeometry({
          center: this._positions,
          semiMajorAxis: this._radius,
          semiMinorAxis: this._radius
        }),
      }),
      asynchronous: false,
      releaseGeometryInstances: false
    })

    this.mounted()
  }

  mounted() {
    this.radius = this._radius
    this.positions = this._positions
    this.style = this._style
    !this.delegate.appearance && this.setAppearance({ type: 'Color' })
  }

  /**
   * 
   * @param {*} style 
   * @returns 
   */

  setStyle(style) {
    if (!style) return
    Object.assign(this._style, { ...style })
    Object.assign(this.delegate, {
      ...this._style
    })
  }

  get radius() {
    return this._radius
  }

  set radius(val) {
    this._radius = val
    this.delegate.geometryInstances.geometry.semiMajorAxis = this._radius
    this.delegate.geometryInstances.geometry.semiMinorAxis = this._radius
  }

  get positions() {
    return this._positions
  }

  set positions(val) {
    this._positions = val
  }
}
